<template>
  <div class="contain">
    <!-- 搜索 -->
    <el-form :model="query" ref="queryForm" :inline="true" class="top-search" label-position="left">
      <el-form-item label="园区名" prop="sender">
        <el-input v-model="query.gardenName" placeholder="请输入" clearable />
      </el-form-item>
      <el-form-item label=" ">
        <el-button type="primary" @click="getList()">查询</el-button>
      </el-form-item>
    </el-form>
    <!-- 操作菜单 -->
    <div class="mid-action">
      <div>
        <!-- <el-button type="primary" size="mini" @click="creatItem('creat')">添加</el-button> -->
      </div>
    </div>
    <!-- 表格列表 -->
    <el-table v-loading="loading" :data="list">
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="缩略图" align="center" prop="parkIntroduceImg" width="140px">
        <template slot-scope="scope">
          <el-image :src="scope.row.parkIntroduceImg" fit="cover" style="width:120px;height:80px;"></el-image>
        </template>
      </el-table-column>
      <el-table-column label="园区名" align="center" prop="name" />
      <el-table-column label="物业" align="center" prop="propertyCompany" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" width="280">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="updateItem(scope.row)">审核</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="query.pageNum"
      :limit.sync="query.pageSize"
      @pagination="getList()"
    />
    <!-- 编辑表单 -->
    <el-dialog title="审核" :visible.sync="editFormShow">
      <el-form class="edit_form" :model="form" ref="form" label-width="100px" label-position="right">
        <el-form-item label="园区图片" prop="parkIntroduceImg">
            <el-image v-if="form.parkIntroduceImg" :src="form.parkIntroduceImg" fit="cover" style="width:376px;height:195px;"></el-image>
        </el-form-item>
        <el-form-item label="园区介绍" prop="companyProfile">
          <el-input class="input" type="textarea" disabled v-model="form.companyProfile" placeholder="请输入" clearable  />
        </el-form-item>
        <el-form-item label="地理位置" prop="location">
          <el-input class="input" type="textarea" disabled v-model="form.location" placeholder="请输入" clearable  />
        </el-form-item>
        <el-form-item label="位置周边" prop="ambitus">
          <el-input class="input" v-model="form.ambitus" disabled placeholder="请输入" clearable  />
        </el-form-item>
        <el-form-item label="宣传视频" prop="publicityVideo">
          <video v-if="form.publicityVideo" :src="form.publicityVideo" style="width:372px;height:195px;" controls></video>
        </el-form-item>
        <el-form-item label="宣传册" prop="brochure">
          <el-link type="success" :href="form.brochure" target="_blank">查看</el-link>
        </el-form-item>
        <el-form-item label="荣誉资质" prop="honorCertification">
          <el-image v-for="(item,index) in form.honorCertification.split(',')" :key="index" :src="item"></el-image>
        </el-form-item>
        <el-form-item label="审核状态">
          <el-radio-group v-model="form.check" size="small">
            <el-radio :label="'0'" border>待审核</el-radio>
            <el-radio :label="'1'" border>审核通过</el-radio>
            <el-radio :label="'2'" border>审核拒绝</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submit()">提交</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

  </div>
</template>

<script>
import { getParkInfoEditList, getParkDetail,  updateParkExamined } from "@/api/eh-api";
import { getToken } from "@/utils/auth";
import { Form } from 'element-ui';
export default {
  data() {
    return {
        // 遮罩层
        loading: false,
        // 总条数
        total: 0,
        // 查询参数
        query: {
            pageNum: 1,
            pageSize: 10,
            gardenName: undefined,
        },
        list:[],
        editFormShow:false,
        form:{
            id: "",
            cardId: "",
            ambitus: "",
            brochure: "",
            companyProfile: "",
            honorCertification: "",
            location: "",
            parkIntroduceImg: "",
            publicityVideo: "",
            check: 0,
        },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /**
     * 获取列表
     */
    getList() {
      this.loading = true;
      getParkInfoEditList(this.query)
        .then(({ rows, total }) => {
          this.list = rows;
          this.total = parseInt(total);
          this.loading = false;
        })
        .catch(() => {
          this.loading = false;
        });
    },

    /**
     * 添加
     */
    updateItem:function(item) {
        this.editFormShow = true
        getParkDetail({
            id: item.id
        }).then( res => {
          let form = this.form
          for( let key in this.form ){
            form[key] = res.data[key]
            form.check = '0'
          }
          form.cardId = item.cardId
          this.form = form
          // console.log('form', this.form, item)
        })
    },

    /**
     * 提交表单
     */
    submit:function(params){
      let form = {}
      form.cardId = this.form.cardId
      form.check = this.form.check
      form.gardenId = this.form.id

      updateParkExamined(form).then( res => {
        if( res.code == 200 ){
          this.$message({
            message: '编辑成功',
            type: 'success'
          })
          this.getList()
        }else{
          this.$message.error(res.msg)
        }
      })

      this.editFormShow = false
    },

  },
};
</script>

<style lang="scss" scoped>
.mid-action {
  display: flex;
  justify-content: space-between;
  margin: 10px 0;
  align-items: center;
  .total {
    background-color: rgba(65, 133, 244, 0.1);
    border: 1px solid rgba(65, 133, 244, 0.2);
    border-radius: 3px;
    font-size: 14px;
    min-height: 32px;
    line-height: 32px;
    padding: 0 12px;
    color: #606266;
  }
  .num {
    color: #00f;
  }
}
.thumbnail {
  width: 160px;
  height: 80px;
}
.input{
  width: 80%;
}

/**头像 */
.avatar-uploader /deep/.el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}
.avatar-uploader /deep/.el-upload:hover {
    border-color: #409EFF;
}
.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 128px;
    height: 128px;
    line-height: 128px;
    text-align: center;
}
.avatar {
    width: 128px;
    height: 128px;
    display: block;
}
</style>
